package com.example.demo.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author vaintale
 * @date 2025/6/25
 */
public class PythonCaller {
    public static void main(String[] args) {
        //String pythonScriptPath = "path/to/facets_redis_producer.py";
        String pythonScriptPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/scripts/Tets.py";
        String networkPath = "network.gml";
        String flowPath = "flow.csv";
        String targetPath = "target.csv";
        String attackTargetPath = "attack.csv";

        try {
            ProcessBuilder pb = new ProcessBuilder(
                    "/home/vaintale/miniconda3/envs/DGM/bin/python3",
                    pythonScriptPath,
                    networkPath,
                    flowPath,
                    targetPath,
                    attackTargetPath
            );
            Process process = pb.start();

            // 捕获 Python 脚本的输出（可选）
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(process.getInputStream())
            );
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println("Python输出: " + line);
            }

            int exitCode = process.waitFor();
            System.out.println("Python脚本执行完毕，退出码: " + exitCode);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
